import CodeBlock from "@theme/CodeBlock";

import Hex from "!!raw-loader!./14.formatting-specifiers-hex.zig";
import Decimal from "!!raw-loader!./14.formatting-specifiers-decimal.zig";
import Ascii from "!!raw-loader!./14.formatting-specifiers-ascii.zig";
import ByteSizes from "!!raw-loader!./14.formatting-specifiers-byte-sizes.zig";
import BinaryOctal from "!!raw-loader!./14.formatting-specifiers-binary-octal.zig";
import Pointer from "!!raw-loader!./14.formatting-specifiers-pointer.zig";
import Scientific from "!!raw-loader!./14.formatting-specifiers-scientific.zig";
import Strings from "!!raw-loader!./14.formatting-specifiers-strings.zig";

# Formatting specifiers

[`std.fmt`](https://ziglang.org/documentation/master/std/#std.fmt) provides
options for formatting various data types.

From here on, we'll be using `std.testing.expectEqualStrings`. This prints out
information if our strings aren't equal, and better conveys our intent over
using `std.testing.expect` and `std.mem.eql`. It's worth noting that the
"strings" we're operating on are just `[]const u8` values where we trust that
the buffer is valid UTF-8.

`std.fmt.fmtSliceHexLower` and `std.fmt.fmtSliceHexUpper` provide hex formatting
for strings as well as `{x}` and `{X}` for ints.

<CodeBlock language="zig">{Hex}</CodeBlock>

`{d}` performs decimal formatting for numeric types.

<CodeBlock language="zig">{Decimal}</CodeBlock>

`{c}` formats a byte into an ascii character.

<CodeBlock language="zig">{Ascii}</CodeBlock>

`std.fmt.fmtIntSizeDec` and `std.fmt.fmtIntSizeBin` output memory sizes in
metric (1000) and power-of-two (1024) based notation.

<CodeBlock language="zig">{ByteSizes}</CodeBlock>

`{b}` and `{o}` output integers in binary and octal format.

<CodeBlock language="zig">{BinaryOctal}</CodeBlock>

`{*}` performs pointer formatting, printing the address rather than the value.

<CodeBlock language="zig">{Pointer}</CodeBlock>

`{e}` outputs floats in scientific notation.

<CodeBlock language="zig">{Scientific}</CodeBlock>

`{s}` outputs strings.

<CodeBlock language="zig">{Strings}</CodeBlock>

This list is non-exhaustive.
